<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>分类列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	body {background: rgb(254,238,189);}
	table {font-family: 宋体; font-size: 11pt; border-color: rgb(78,78,78);  width: 60%;}
	#th {background: rgb(78,78,78);}
</style>
	  <script type="text/javascript" src="/adminjsps/js/jquery-3.2.1.min.js"></script>
	  <script type="text/javascript" src="/adminjsps/js/jquerysession.js"></script>
  </head>
  
  <body>
    <h2 style="text-align: center;">分类列表</h2>
    <table align="center" border="1" cellpadding="0" cellspacing="0">
		<thead>
		<tr id="th" bordercolor="rgb(78,78,78)">
			<th>分类名称</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		<%--<tr bordercolor="rgb(78,78,78)">--%>
			<%--<td>JavaSE</td>--%>
			<%--<td>--%>
				<%--<a href="<c:url value='/adminjsps/admin/category/mod.jsp'/>">修改</a> |--%>
				<%--<a href="<c:url value='/adminjsps/admin/category/del.jsp'/>">删除</a>--%>
			<%--</td>--%>
		<%--</tr>--%>
		</tbody>
		<%--<input type="button" class="btn" value="跳转">--%>
    </table>
	<script>
		window.onload=function () {
			$.ajax({
				url:"/category",
				type:"get",
				success:function (re) {
					console.log(re);
					console.log(re.data.length);
					var i;
					for (i = 0; i < re.data.length; i++) {
						console.log(i);
						var cate = $("<td>"+re.data[i].cname+"</td>");
						var done = $("<td><a href='/adminjsps/admin/category/mod.jsp?cname'>\"+修改+\"</a>" +
								"<a href='/adminjsps/admin/category/del.jsp?cname'>\"+删除+\"</a>" +
								"</td>");
						$("<tr bordercolor=\"rgb(78,78,78)\"></tr>").append($("<td>"+re.data[i].cname+"</td>"))
								.append($("<td><input type='button' class='"+re.data[i].cid+"' id='change' value='修改'>" +
										"<input type='button' class='"+re.data[i].cid+"' id='del' value='删除'></td>"))
								.appendTo("tbody")
					}
				}
			})
		};
		$("tbody").on("click","input",function () {
			console.log($(this).attr("class"));
			var cid = $(this).attr("class");
			var road = $(this).attr("id");
			$.ajax({
				url:"/catesession",
				type:"get",
				data:{
					cid:cid
				},
				success:function (re) {
					if (re.code == 1000) {
						console.log(re);
						if (road == "change") {
							location.href="/adminjsps/admin/category/mod.jsp"
						}else if (road == "del") {
							location.href="/adminjsps/admin/category/del.jsp"
						}
					}
				}
			})
		})
	</script>
  </body>
</html>
